package com.study.ws.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

/**
 * @author xl-9527
 * @since 2025/3/23
 **/
@Controller
public class StompMessageController {

    private final Logger log = LoggerFactory.getLogger(StompMessageController.class);

    private final SimpMessagingTemplate simpMessagingTemplate;

    public StompMessageController(final SimpMessagingTemplate simpMessagingTemplate) {
        this.simpMessagingTemplate = simpMessagingTemplate;
    }

    @MessageMapping("/greeting")
    public String appHello(String message) {
        log.warn("greeting message mapping is running");
        simpMessagingTemplate.convertAndSendToUser("1", "/test", "system: i receive message -> [" + message + "]");
        return "system: i receive message -> [" + message + "]";
    }
}
